// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_bigint_from_decimal256_76_38") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "set enable_decimal256 = true;"
    sql "drop table if exists test_cast_to_bigint_from_decimal256_76_38_0_nullable;"
    sql "create table test_cast_to_bigint_from_decimal256_76_38_0_nullable(f1 int, f2 decimalv3(76, 38)) properties('replication_num'='1');"
    sql """insert into test_cast_to_bigint_from_decimal256_76_38_0_nullable values (0, "0.00000000000000000000000000000000000000"),(1, "0.00000000000000000000000000000000000001"),(2, "0.00000000000000000000000000000000000009"),(3, "0.99999999999999999999999999999999999999"),(4, "0.99999999999999999999999999999999999998"),(5, "0.09999999999999999999999999999999999999"),(6, "0.90000000000000000000000000000000000000"),(7, "0.90000000000000000000000000000000000001"),(8, "1.00000000000000000000000000000000000000"),(9, "1.00000000000000000000000000000000000001"),(10, "1.00000000000000000000000000000000000009"),(11, "1.99999999999999999999999999999999999999"),(12, "1.99999999999999999999999999999999999998"),(13, "1.09999999999999999999999999999999999999"),(14, "1.90000000000000000000000000000000000000"),(15, "1.90000000000000000000000000000000000001"),(16, "9.00000000000000000000000000000000000000"),(17, "9.00000000000000000000000000000000000001"),(18, "9.00000000000000000000000000000000000009"),(19, "9.99999999999999999999999999999999999999"),
      (20, "9.99999999999999999999999999999999999998"),(21, "9.09999999999999999999999999999999999999"),(22, "9.90000000000000000000000000000000000000"),(23, "9.90000000000000000000000000000000000001"),(24, "9223372036854775807.00000000000000000000000000000000000000"),(25, "9223372036854775807.00000000000000000000000000000000000001"),(26, "9223372036854775807.00000000000000000000000000000000000009"),(27, "9223372036854775807.99999999999999999999999999999999999999"),(28, "9223372036854775807.99999999999999999999999999999999999998"),(29, "9223372036854775807.09999999999999999999999999999999999999"),(30, "9223372036854775807.90000000000000000000000000000000000000"),(31, "9223372036854775807.90000000000000000000000000000000000001"),(32, "9223372036854775806.00000000000000000000000000000000000000"),(33, "9223372036854775806.00000000000000000000000000000000000001"),(34, "9223372036854775806.00000000000000000000000000000000000009"),(35, "9223372036854775806.99999999999999999999999999999999999999"),(36, "9223372036854775806.99999999999999999999999999999999999998"),(37, "9223372036854775806.09999999999999999999999999999999999999"),(38, "9223372036854775806.90000000000000000000000000000000000000"),(39, "9223372036854775806.90000000000000000000000000000000000001"),
      (40, "-9223372036854775808.00000000000000000000000000000000000000"),(41, "-9223372036854775808.00000000000000000000000000000000000001"),(42, "-9223372036854775808.00000000000000000000000000000000000009"),(43, "-9223372036854775808.99999999999999999999999999999999999999"),(44, "-9223372036854775808.99999999999999999999999999999999999998"),(45, "-9223372036854775808.09999999999999999999999999999999999999"),(46, "-9223372036854775808.90000000000000000000000000000000000000"),(47, "-9223372036854775808.90000000000000000000000000000000000001"),(48, "-9223372036854775807.00000000000000000000000000000000000000"),(49, "-9223372036854775807.00000000000000000000000000000000000001"),(50, "-9223372036854775807.00000000000000000000000000000000000009"),(51, "-9223372036854775807.99999999999999999999999999999999999999"),(52, "-9223372036854775807.99999999999999999999999999999999999998"),(53, "-9223372036854775807.09999999999999999999999999999999999999"),(54, "-9223372036854775807.90000000000000000000000000000000000000"),(55, "-9223372036854775807.90000000000000000000000000000000000001")
      ,(56, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as bigint) from test_cast_to_bigint_from_decimal256_76_38_0_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as bigint) from test_cast_to_bigint_from_decimal256_76_38_0_nullable order by 1;'

    sql "drop table if exists test_cast_to_bigint_from_decimal256_76_38_0_not_nullable;"
    sql "create table test_cast_to_bigint_from_decimal256_76_38_0_not_nullable(f1 int, f2 decimalv3(76, 38)) properties('replication_num'='1');"
    sql """insert into test_cast_to_bigint_from_decimal256_76_38_0_not_nullable values (0, "0.00000000000000000000000000000000000000"),(1, "0.00000000000000000000000000000000000001"),(2, "0.00000000000000000000000000000000000009"),(3, "0.99999999999999999999999999999999999999"),(4, "0.99999999999999999999999999999999999998"),(5, "0.09999999999999999999999999999999999999"),(6, "0.90000000000000000000000000000000000000"),(7, "0.90000000000000000000000000000000000001"),(8, "1.00000000000000000000000000000000000000"),(9, "1.00000000000000000000000000000000000001"),(10, "1.00000000000000000000000000000000000009"),(11, "1.99999999999999999999999999999999999999"),(12, "1.99999999999999999999999999999999999998"),(13, "1.09999999999999999999999999999999999999"),(14, "1.90000000000000000000000000000000000000"),(15, "1.90000000000000000000000000000000000001"),(16, "9.00000000000000000000000000000000000000"),(17, "9.00000000000000000000000000000000000001"),(18, "9.00000000000000000000000000000000000009"),(19, "9.99999999999999999999999999999999999999"),
      (20, "9.99999999999999999999999999999999999998"),(21, "9.09999999999999999999999999999999999999"),(22, "9.90000000000000000000000000000000000000"),(23, "9.90000000000000000000000000000000000001"),(24, "9223372036854775807.00000000000000000000000000000000000000"),(25, "9223372036854775807.00000000000000000000000000000000000001"),(26, "9223372036854775807.00000000000000000000000000000000000009"),(27, "9223372036854775807.99999999999999999999999999999999999999"),(28, "9223372036854775807.99999999999999999999999999999999999998"),(29, "9223372036854775807.09999999999999999999999999999999999999"),(30, "9223372036854775807.90000000000000000000000000000000000000"),(31, "9223372036854775807.90000000000000000000000000000000000001"),(32, "9223372036854775806.00000000000000000000000000000000000000"),(33, "9223372036854775806.00000000000000000000000000000000000001"),(34, "9223372036854775806.00000000000000000000000000000000000009"),(35, "9223372036854775806.99999999999999999999999999999999999999"),(36, "9223372036854775806.99999999999999999999999999999999999998"),(37, "9223372036854775806.09999999999999999999999999999999999999"),(38, "9223372036854775806.90000000000000000000000000000000000000"),(39, "9223372036854775806.90000000000000000000000000000000000001"),
      (40, "-9223372036854775808.00000000000000000000000000000000000000"),(41, "-9223372036854775808.00000000000000000000000000000000000001"),(42, "-9223372036854775808.00000000000000000000000000000000000009"),(43, "-9223372036854775808.99999999999999999999999999999999999999"),(44, "-9223372036854775808.99999999999999999999999999999999999998"),(45, "-9223372036854775808.09999999999999999999999999999999999999"),(46, "-9223372036854775808.90000000000000000000000000000000000000"),(47, "-9223372036854775808.90000000000000000000000000000000000001"),(48, "-9223372036854775807.00000000000000000000000000000000000000"),(49, "-9223372036854775807.00000000000000000000000000000000000001"),(50, "-9223372036854775807.00000000000000000000000000000000000009"),(51, "-9223372036854775807.99999999999999999999999999999999999999"),(52, "-9223372036854775807.99999999999999999999999999999999999998"),(53, "-9223372036854775807.09999999999999999999999999999999999999"),(54, "-9223372036854775807.90000000000000000000000000000000000000"),(55, "-9223372036854775807.90000000000000000000000000000000000001");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as bigint) from test_cast_to_bigint_from_decimal256_76_38_0_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as bigint) from test_cast_to_bigint_from_decimal256_76_38_0_not_nullable order by 1;'

}